import moment from "moment";

// 日期过滤 如 2018-12-20
export function dateFilters(time) {
    if (time) {
        return time.slice(0, 10);
    }
    return time;
}

// 日期过滤 如 2018-12-20
export function dateFormat(time) {
    if (time) {
        return moment(time).format("YYYY年MM月DD日");
    }
    return time;
}

// 图片路劲
export function imgUrl(url) {
    if (url) {
        return "" + url;
    }
    return url;
}
// 默认图片
export function defImgUrl(url) {
    if (url) {
        return url;
    }
    return require("@/assets/img/avatar.png");
}

// 字符串转数组
export function splitArray(val) {
    if (val) {
        return val.split(",");
    }
    return val;
}
// 隐藏手机中间四位
export function pheonfiles(val) {
    if (val) {
        val = val.substr(0, 3) + "****" + val.substr(7);
        return val;
    }
    return val;
}

// 字符串转数组
export function workTypeFilter(val) {
    const workTypeList = [{
            name: "全制",
            id: "1",
        },
        {
            name: "兼职",
            id: "2",
        },
        {
            name: "零时工",
            id: "3",
        },
        {
            name: "合同工",
            id: "4",
        },
    ];
    if (val) {
        let list = workTypeList.filter((item) => {
            return item.id == val;
        });
        return list[0].name;
    }
    return "全制";
}

// 政策标签
export function policyLabelfiles(val) {
    if (val) {
        return val.split(",");
    }
    return val;
}